library(methods)
library(xcms)

#default
fwhm = 30 
sigma = fwhm/2.3548
max = 5 
snthresh = 10 
step = 0.1
steps = 2
mzdiff = 0.8 - step*steps


args <- commandArgs(TRUE)
nb_files <- as.numeric(args[1])
xmlfiles <- args [2:(nb_files+1)]
retcor <- args[length(args)]
args <- args [(length(xmlfiles)+2):(length(args)-1)] 
for (i in 1:length(args)) {
	if ((as.numeric(args[i])) != 0) {
		if (i == 1) fwhm <- as.numeric(args[i])
		else if (i==2) step <- as.numeric(args[i])
		else if (i == 3) steps <- as.numeric(args[i])
		else if (i==4) mzdiff<- as.numeric(args[i])
		else if (i==5) snthresh <- as.numeric(args[i])
		else if (i==6) max <- as.numeric(args[i])
	}
}

set <- xcmsSet(xmlfiles,  fwhm = fwhm, snthresh = snthresh,  step = step, steps = steps, mzdiff = mzdiff, max = max) #, profstep = 1, profmethod = "intlin", profparam =list(), includeMSn=FALSE
groupedset <- group(set)
#if (retcor) {
print ("Time Retention Correction")
retset =retcor(groupedset, method =  retcor)
#}
write.table(peaks(retset), paste("peaks"), sep=';', quote = FALSE,  col.names = TRUE, row.names=FALSE)

#return (peaks)






